//
//  HotModel.swift
//  FirstSwiftProduct
//
//  Created by 范泽华 on 2017/11/2.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

class HotModel: NSObject {

    
    var lives = [livess]()
    
    
//    var lives = [livess]()
    
    func getModelData(success:@escaping(String)->()) -> Void {
        
        HttpTool.shareTool.requestJsonDataWithUrl(Type: .get, url: kHotLiveAPI, parames: [:], succeed: { (successMessage, result) in
            
            let model = HotModel.model(withJSON: result as AnyObject)
            self.lives = (model?.lives)!
            success("yes")
//            print(result as Any)
        }, error: { (error) in
            print(error!)
        }) { (failMessage) in
            print(failMessage!)
        }
        
    }
    
    static func modelContainerPropertyGenericClass() -> [String : AnyObject]? {
        return ["lives"    : livess.self]
    }
    
}

class livess: NSObject {
    
    /** 观看人数 */
    var online_users : String = ""
    /** 城市 */
    var city : String = ""
    /** ID号*/
    var id : String = ""
    /** 直播间名称*/
    var name : String = ""
    //直播间ID
    var room_id : String = ""
    //距离
    var distance : String = ""
    
    /** 直播流地址 */
    public var stream_addr = String() {
        didSet {
            if !stream_addr.hasPrefix("http") {
//                self.stream_addr = kTJPCommonServiceAPI + self.stream_addr
            }
        }
    }
    /** 分享地址*/
    public var share_addr = String() {
        didSet {
            if !share_addr.hasPrefix("http") {
//                self.share_addr = kTJPCommonServiceAPI + self.share_addr
            }
        }
    }
    
    /** 主播信息 */
    var creator : creators?
    /** 扩展属性*/
    var extra : extras?
    
    static func modelContainerPropertyGenericClass() -> [String : AnyObject]? {
        return ["creator"    : creators.self,
                "extra"  : extras.self]
    }
}
//主播个人信息
class creators: NSObject {
    /**
     creator =         {
     gender = 0;
     id = 85882548;
     level = 394;
     nick = "\Ud83d\Udc1b\U4e24\U7c73\U5927\U4e2a\U5343\U91d1-\Ud83c\Udd71\Ufe0f";
     portrait = "http://img2.inke.cn/MTUwOTAxMDgxMzg0MSM1MDkjanBn.jpg";
     };

     */
    var id : String = ""
    var level : String = ""
    var gender : String = ""
    var nick : String = ""
    
    public var portrait = String() {
        didSet {
            if !portrait.hasPrefix("http") {
                self.portrait = "http://img.meelive.cn/" + self.portrait
            }
        }
    }
}
//标签
class extras: NSObject {
    /**
     cover = "<null>";
     label =             (
     {
     cl =                     (
     0,
     216,
     201,
     1
     );
     "tab_key" = "\U597d\U58f0\U97f3";
     "tab_name" = "\U597d\U58f0\U97f3";
     },
     {
     cl =                     (
     0,
     216,
     201,
     1
     );
     "tab_key" = "\U6c14\U8d28";
     "tab_name" = "\U6c14\U8d28";
     },
     {
     cl =                     (
     0,
     216,
     201,
     1
     );
     "tab_key" = "\U5fa1\U59d0";
     "tab_name" = "\U5fa1\U59d0";
     },
     {
     cl =                     (
     0,
     216,
     201,
     1
     );
     "tab_key" = "\U706b\U661f";
     "tab_name" = "\U706b\U661f";
     }
     );
     */
    
    var label = [labelst]()
    
    static func modelContainerPropertyGenericClass() -> [String : AnyObject]? {
        return ["label"    : labelst.self]
    }
}

class labelst: NSObject {
    var tab_name : String = ""
    var tab_key : String = ""
}
